/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stringhelper;

import java.util.ArrayList;

/**
 *
 * @author Welcome
 */
public abstract class SQLStatement {
    protected ArrayList<String> keyWords;
    protected String strStatement;
    protected String[] tempField;
    protected String[] tempTable;
    protected KindOfStatement kindOfStatement;

    public KindOfStatement getKindOfStatement() {
        return kindOfStatement;
    }

    public String[] getTempField() {
        return tempField;
    }

    public String[] getTempTable() {
        return tempTable;
    }
    
    
    public String getContentAfter(String startString) throws Exception
    {
        String temp="";
        for(int i=0; i<keyWords.size();i++)
        {
            if(keyWords.get(i)==startString && i<keyWords.size()-1)
            {
                temp = keyWords.get(i+1);
            }
        }
        
        return getStringInMidle(startString, temp);
    }
    
    public String getStringInMidle(String strBegin, String strEnd) throws Exception
    {
        int tempBegin = strStatement.indexOf(strBegin); //danh dau vi tri bat dau
        int tempEnd = strStatement.indexOf(strEnd);     //danh dau vi tri kest thuc
        
        String result="";
        
        if(strBegin=="")
        {
            tempBegin =-1;
        }
        if (strEnd=="")
        {
            tempEnd =-1;
        }
        
        if (tempBegin !=-1) //co vi tri bat dau
        {
            if (tempEnd!=-1)
            {
                result= strStatement.substring(tempBegin+strBegin.length(), tempEnd).trim();
            }
            else
            {
                result= strStatement.substring(tempBegin+strBegin.length()).trim();
            }
        }
        else 
        {
            if (tempEnd!=-1)
            {
                result= strStatement.substring(0,tempEnd).trim();
            }
            else
            {
                //return null;
            }
        }
        if(result.equals(""))
            return null;
        else
            return result;
        //return null;
    }
    
    public String[] CutSign(String content)
    {
        if(content == null)
            return null;
        String[] result = null;
        
        result = content.split(",");
        for(int i=0; i<result.length; i++)
        {
            result[i].trim();
        }
        return result;
    }
    public abstract void getData()throws Exception;
    
        
    
}
